home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
013
/
menus.arc
/
MENUS.DOC
< prev
next >
Wrap
Text File
|
1987-04-13
|
38KB
|
1,010 lines
M E N U S
Version 1.0
A Menu Programming Language
(C) Copyright 1987, All Rights Reserved
By
Paul A Parker
Page 2
CONTENTS
1. INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2. PROGRAM STRUCTURE . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.1. Menu File Requirements . . . . . . . . . . . . . . . . . . . . 4
2.2. Invoking the Program . . . . . . . . . . . . . . . . . . . . . 4
2.3. Introduction to Menus Programming . . . . . . . . . . . . . . 4
2.4. Formatted Menu Structure . . . . . . . . . . . . . . . . . . . 4
2.5. Un-formatted Menu Structure . . . . . . . . . . . . . . . . . 6
2.6. Interactive Batch Structure . . . . . . . . . . . . . . . . . 6
3. MENU FUNCTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.1. Menu Control . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.1.1. Menudef{} . . . . . . . . . . . . . . . . . . . . . 7
3.1.2. Select{} . . . . . . . . . . . . . . . . . . . . . . 7
3.1.3. Menu{} . . . . . . . . . . . . . . . . . . . . . . . 7
3.2. Program Control . . . . . . . . . . . . . . . . . . . . . . . 7
3.2.1. Quit{} . . . . . . . . . . . . . . . . . . . . . . . 7
3.2.2. Nobreak{} . . . . . . . . . . . . . . . . . . . . . 7
3.2.3. Password{} . . . . . . . . . . . . . . . . . . . . . 8
3.2.4. Ifdir{} . . . . . . . . . . . . . . . . . . . . . . 8
3.2.5. Ifndir{} . . . . . . . . . . . . . . . . . . . . . . 9
3.2.6. Iffile{} . . . . . . . . . . . . . . . . . . . . . . 9
3.2.7. Ifnfile{} . . . . . . . . . . . . . . . . . . . . . 9
3.2.8. Ifset{} . . . . . . . . . . . . . . . . . . . . . . 9
3.2.9. Ifnset{} . . . . . . . . . . . . . . . . . . . . . . 10
3.3. Console I/O . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3.1. Prompt{} . . . . . . . . . . . . . . . . . . . . . . 11
3.3.2. Input{} . . . . . . . . . . . . . . . . . . . . . . 11
3.3.3. Wait{} . . . . . . . . . . . . . . . . . . . . . . . 11
3.3.4. Getkey{} . . . . . . . . . . . . . . . . . . . . . . 12
3.3.5. Option{} . . . . . . . . . . . . . . . . . . . . . . 12
3.3.6. Screen{} . . . . . . . . . . . . . . . . . . . . . . 12
3.3.7. Timedisp{} . . . . . . . . . . . . . . . . . . . . . 12
3.3.8. Title{} . . . . . . . . . . . . . . . . . . . . . . 12
3.3.9. Color{} . . . . . . . . . . . . . . . . . . . . . . 13
3.4. Dos Calls . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.4.1. Command{} . . . . . . . . . . . . . . . . . . . . . 13
4. EXAMPLES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.1. Printer Setup Program . . . . . . . . . . . . . . . . . . . . 15
4.2. Typewriter Program . . . . . . . . . . . . . . . . . . . . . . 16
4.3. DOS Interface Menu . . . . . . . . . . . . . . . . . . . . . . 17
5. PROGRAM SPECIFICATIONS . . . . . . . . . . . . . . . . . . . . . . 21
5.1. Hardware Requirements . . . . . . . . . . . . . . . . . . . . 21
5.2. Memory Requirements . . . . . . . . . . . . . . . . . . . . . 21
5.2.1. DOS Calls with Command{} . . . . . . . . . . . . . . 21
5.2.2. Menu Definitions and Getkey Options . . . . . . . . 21
5.2.3. Program Statements . . . . . . . . . . . . . . . . . 21
5.2.4. Internal Requirements . . . . . . . . . . . . . . . 21
5.3. Program Limitations . . . . . . . . . . . . . . . . . . . . . 22
Page 3
1. INTRODUCTION
First I will give a little history of Menus. I have been programming in C
for about two years, and have taught myself everything I know about C.
This program started as an experiment with function pointers and
developed into a simple programming language.
The Menu Program reads an ASCII text command file and tokenizes it into
function pointers with parameters in a doubly linked list of elements. The
program then calls each function starting with the first element read, and
continues until the quit function is issued. There are some provisions for
program flow control and conditional testing, but they are severly limited
in their scope.
The language currently has twenty two functions and may be enhanced in
the future. I'll admit there are limits to the language, but they allow
enough room for the language to be usable. Each limitation will be
explained with the appropriate function.
There is one thing that should be noted. This program expects the
ansi.sys device driver to be installed if the menus are used or when any
screen formatting is done. The program uses the driver to set colors, and
control how messages are printed to the screen. This requirement may
change in the future.
Page 4
2. PROGRAM STRUCTURE
2.1. Menu File Requirements
The menu file must be Ascii format with line lengths shorter than 256
characters. There may be only one command per line in upper or lower
case, with the command parameters immediately following the command,
surrounded by curly braces. Comments may be placed anywhere outside
the curly braces and are ignored by the program.
Example: command{DIR} display the current directory
2.2. Invoking the Program
There are several ways the program may be invoked. It may be invoked
with or without command line parameters. The parameters are the file
name and silence switch, and may be placed in any order. If there are no
command line parameters, the program searches for the default menu file
"MENU.MNU" in the root directory. If the silence switch is used, the
copyright notice and other messages are silenced when the program is
being loaded.
Examples: C>menu /s
2.3. Introduction to Menus Programming
Menus is a "functional" language, meaning that each statement is actually
a call to a function. The language can take three basic forms that each
act entirely different. The first form is the formatted menu structure
with menu definitions and selections. The second form is the unformatted
menu structure with menu definitions but no selections. The third form is
the interactive batch structure with no menu definitions or selections.
2.4. Formatted Menu Structure
The formatted menu structure displays the menus in a predefined format
on the screen. There are five different windows on the menu screen that
can be controlled. Each window is flexible to some extent, but there are
size limitations.
At the top of the screen is the major title window, where three major
title lines may be displayed. The titles are enclosed in a single line box,
so two extra lines are taken from the screen when major titles are used.
The major titles will remain on the menu screen for the duration of the
menu program. Immediately following the major menu is a double line box
enclosing the remainder of the screen. If no major titles are used the box
encloses the entire screen.
The menu title window is surrounded by a single line box and appears
directly below the major title window on the inside of the double line box
surrounding the screen. There can be a maximum of two menu title lines
Page 5
in the window, and if there are no menu titles, the menu title window is
not displayed.
The area below the menu title and above the prompt and input lines is
used for menu selections. The current selection prompt is on the bottom
line of this window. Currently there is no provision for selection
scrolling, so the number of selections is limited by the screen size. The
other two windows are the prompt and input windows that appear
respectivly as the last two lines below the selection prompt line.
Example: screen{off}
title{Menus Major Title}
menudef{0}
title{Menu One}
select{Quit Menus}
quit{}
select{Menu Two}
menu{1}
select{Menu Three}
menu{3}
menudef{1}
title{Menu Two}
select{Menu One}
menu{0}
select{Sub-Menu One}
menu{2}
menudef{2}
title{Sub-Menu One}
select{Menu Two}
menu{1}
menudef{3}
title{Menu Three}
select{Menu One}
menu{0}
Page 6
2.5. Un-formatted Menu Structure
The unformatted menu structure has limited display formatting and no
menu selections, menu definitions are used more for program flow control.
They act as labels for procedures. Caution, the last function in the menu
file must be a quit, or a call to a menu definition, otherwise a runtime
error will occur.
Example: menudef{0}
getkey{Press <ESC> to quit, <RETURN> to run dos command.}
option{27}
quit{}
option{13}
prompt{}
input{0,Enter command: }
command{%0}
menu{0}
2.6. Interactive Batch Structure
The interactive batch structure has no menu definitions or selections. The
program starts at the first function read and terminates with the quit
function. Failure to include the quit may result in a runtime error.
Example: input{0,1w,Enter first name: }
input{1,1c,Enter middle initial: }
input{2,1w,Enter last name: }
prompt{}
command{echo %0 %1. %2}
quit{}
Page 7
3. MENU FUNCTIONS
3.1. Menu Control
3.1.1. Menudef{}
Syntax: menudef{number}
This function begins the definition of a menu
identified by number. Currently only menus 0-
19 can be defined. For examples refer to the
Program Structure and Examples sections of this
manual.
3.1.2. Select{}
Syntax: select{title}
This function defines the beginning of a menu
selection and must follow a menudef{}.
Currently the number of selections is limited by
the size of the screen. Future enhancements
will allow menu selections to scroll up and down
in the available space. For examples refer to
the Program Structure and Examples sections of
this manual.
3.1.3. Menu{}
Syntax: menu{number/path}
This function passes control to the menu that is
identified by number, or loads the menu defined
by path. An error occurs if the menu number is
not defined, or the program cannot find the
menu file.
3.2. Program Control
3.2.1. Quit{}
Syntax: quit{message}
This function terminates the operation of the
menu system, prints the message and returns to
the calling program.
Example: quit{Goodbye.}
Page 8
3.2.2. Nobreak{}
Syntax: nobreak{password}
This function set the Control-Break level. If
this command is not issued, then the user is
prompted if they want to break. If this
command is issued and password is blank, then
no break is allowed. If a break is requested and
a password is present the password must be
given first before the program will break. A
word of caution; if a break is issued at the dos
level and a password is required, the program
will stop until the password is entered.
Example: nobreak{ }
3.2.3. Password{}
Syntax: password{password}
This function requires the password to be
entered before the program will continue. If the
menu screen is present, then the user is given
three tries before they are returned to the
current menu or calling program. Caution if a
password is issued with the dos screen on, then
the password must be entered before the
program continues.
Example: password{#}
3.2.4. Ifdir{}
Syntax: ifdir{path,message}
If the path exists, then the message is printed
and control is returned to the current menu or
calling program.
Example: ifdir{c:\dos,ERROR: DOS exists!}
Page 9
3.2.5. Ifndir{}
Syntax: ifndir{path,message}
If the path does not exists, then the message is
printed and control is returned to the current
menu or calling program.
Example: ifndir{c:\dos,ERROR: DOS does not exist!}
3.2.6. Iffile{}
Syntax: iffile{pathname,message}
If the file exists, then the message is printed
and control is returned to the current menu or
calling program.
Example: iffile{command.com,COMMAND.COM exists!}
3.2.7. Ifnfile{}
Syntax: ifnfile{pathname,message}
If the file does not exists, then the message is
printed and control is returned to the current
menu or calling program.
Example: ifnfile{wp.exe,WP.EXE not found!}
3.2.8. Ifset{}
Syntax: ifset{name=value,message}
If the environment variable name exists and is
equal to the value, then the message is printed
and control is returned to the current menu or
calling program. The name is required but the
value is not. If the variable exists and a value
was not specified then the program assumes the
value is equal regardless and the program returns
to the current menu or calling program.
Example: ifset{comspec=c:\command.com,Boot from Floppy!}
Page 10
3.2.9. Ifnset{}
Syntax: ifnset{name=value,message}
If the environment variable name exists and is
not equal to the value, then the message is
printed and control is returned to the current
menu or calling program. The name is required
but the value is not. If the variable does not
exist and a value was not specified then the
program returns to the current menu or calling
program.
Example: ifnset{userid,ERROR: User Id unknown!}
Page 11
3.3. Console I/O
3.3.1. Prompt{}
Syntax: prompt{message}
This function prints a message on the prompt
line when the menu is showing, or if the dos
screen is showing, it prints the message on next
available line. Ansi.sys may be used by the
prompt function to format the screen.
Example: prompt{^[[2J} clear screen. ^[ is Ascii Esc.
3.3.2. Input{}
Syntax: input{number,format,message}
This function prints the message and waits for
the user to enter information into a variable
defined by number. Currently only variables 0-
9 are available and have a maximum length of 80
characters. The format is optional and defines
what information is accepted. Format begins
with a decimal value and ends with a "C" or "W".
If a "C" is specified, then the number specified
in the format is the maximum number of
characters read. If a "W" is specified, then the
number specified in the format is the maximum
number of words read. The variables will be
expanded when included in command{}, as
explained later.
Examples: input{0,12c,Enter file name with extension: }
3.3.3. Wait{}
Syntax: wait{key,message}
This function prints the message and waits for
key to be pressed. If key is equal to zero then
the program waits for any key. Key must be
expressed in Ascii as a decimal value.
Example: wait{0,Press any key to continue.}
Page 12
3.3.4. Getkey{}
Syntax: getkey{message}
This function prints the message and waits for a
key to be hit. If any of the options that follow
have a key that matches, the control is passed
to the command following the appropriate option.
3.3.5. Option{}
Syntax: option{key,key...}
This function defines a key or keys used by the
getkey function. If the key returned by getkey
matches any of the keys listed, then control is
passed to the function following the option. Key
must be expressed in Ascii as decimal values
delimited by commas.
Example: getkey{Answer Y/N}
option{89,121}
prompt{Yes}
option{78,110}
prompt{No}
3.3.6. Screen{}
Syntax: screen{value}
This function turns on and off the dos screen.
If the value is equal to OFF, then the menu
screen is displayed. If the value is equal to ON,
then the dos screen is displayed.
Example: screen{off} turn off dos screen display.
3.3.7. Timedisp{}
Syntax: timedisp{value}
This function turns on and off the time display.
If the value is equal to OFF, then the time and
date is not displayed. If the value is equal to
ON, then the time and date is displayed.
Example: screen{off} turn off dos screen display.
Page 13
3.3.8. Title{}
Syntax: title{title line}
This function adds a title line to the major title,
or the menu title, depending on the placement of
the function. If the title is before the first
menudef{}, then it is added to the major title,
but a maximum of three are allowed. If the title
is after a menudef{}, the title line is added to
the menu title, but a maximum of two are
allowed. For additional examples, see the
Examples section of this manual.
Example: title{Menus Major Menu}
3.3.9. Color{}
Syntax: color{foreground,background,border}
This function changes the color of any of the
menu screen sections depending on their
placement. The color function may be placed
before the first major title where it set the dos
color and other prompts. Color function after
the major titles sets the color of the major
titles. Color before the menu title sets the
color for the menu titles, and color after the
menu titles sets the color for the selections.
Colors: Number CGA MGA
0 Black Black
1 Blue Underline White
2 Green White
3 Cyan White
4 Red White
5 Magenta White
6 Brown White
7 White White
8 Gray Black
9 Light blue Underline light white
10 Light green Light white
11 Light cyan Light white
12 Light red Light white
13 Light magenta Light white
14 Yellow Light white
15 Light white Light white
Example: color{7,0,15}
Page 14
3.4. Dos Calls
3.4.1. Command{}
Syntax: command{command line}
This function calls the dos command interpreter
with the command line given. The command line
may contain variables entered by the user. To
use a variable previously entered, place a
percent sign before the number in the command
line. If the percent sign is used by itself it is
ignored, but if there is a number immidiatly
following the percent it will be expanded. If the
number is preceded by two percent signs, then
one is removed and the number is not expanded.
Example: input{0,1w,Enter file to type: }
command{type %0 | more}
quit{}
Page 15
4. EXAMPLES
4.1. Printer Setup Program (batch structure)
Example #1 File name: setup
prompt{^[[2J}
prompt{Printer Setup Program}
prompt{}
prompt{NEC Pinwriter P5/P6/P7}
prompt{}
prompt{<RETURN> to exit}
prompt{}
prompt{1 - 10 pitch}
prompt{2 - 12 pitch}
prompt{3 - 15 pitch}
prompt{4 - 17 pitch}
prompt{5 - 20 pitch}
prompt{}
getkey{Enter selection: }
option{49} '1'
command{echo ^\@^[P> prn}
quit{}
option{50} '2'
command{echo ^\@^[M> prn}
quit{}
option{51} '3'
command{echo ^\@^[g> prn}
quit{}
option{52} '4'
command{echo ^\@^[P^O> prn}
quit{}
option{53} '5'
command{echo ^\@^[M^O> prn}
quit{}
option{13} return
quit{}
Page 16
4.2. Typewriter Program (unformatted menu structure)
Example #2 File name: typewrit
menudef{0}
prompt{^[[2J}
prompt{Typewriter Program}
prompt{}
getkey{<ESC> to quit, <RETURN> for next line.}
option{27}
quit{}
option{13}
prompt{Enter Line:}
input{0}
command{echo %0>prn}
menu{0}
Page 17
4.3. DOS Interface Menu (formatted menu structure)
Example #3 File name: doscmds
screen{off}
color{7,0,15}
title{ DOS COMMAND INTERFACE }
color{15,1,7}
menudef{0} Main Menu
color{14,2,13}
title{ Main Menu }
color{7,0,15}
select{File Commands}
menu{1}
select{Directory Commands}
menu{2}
select{Disk Commands}
menu{3}
select{System Commands}
menu{4}
select{Quit Program}
screen{on}
quit{Bye.}
menudef{1} File Commands
title{ File Commands }
select{Return to Main Menu}
menu{0}
select{<TYPE> Display File}
input{0,1w,Enter pathname: }
screen{on}
prompt{^[[2J}
command{type %0 | more}
wait{0,Press any key to continue.}
screen{off}
select{<COPY> Copy File}
input{0,1w,Enter source pathname: }
input{1,1w,Enter destination pathname: }
prompt{Coping..}
command{copy %0 %1}
prompt{}
select{<COMP> Compare File}
input{0,1w,Enter source pathname: }
input{1,1w,Enter destination pathname: }
screen{on}
prompt{^[[2J}
command{comp %0 %1}
wait{0,Press any key to continue.}
screen{off}
Page 18
menudef{2} Directory Commands
title{ Directory Commands }
select{Return to Main Menu}
menu{0}
select{<DIR> Display Directory}
input{0,Enter directory name: }
screen{on}
prompt{^[[2J}
command{dir %0 | more}
wait{0,Press any key to continue.}
screen{off}
select{<TREE> List Directories}
input{0,1c,Enter drive designation: }
screen{on}
prompt{^[[2J}
command{tree %0 | more}
wait{0,Press any key to continue.}
screen{off}
select{<CHDIR> Change Directory}
input{0,Enter directory name: }
command{cd %0}
select{<MKDIR> Make Directory}
input{0,Enter directory name: }
getkey{Press <ESC> to abort, <RETURN> to continue.}
option{27}
prompt{}
option{13}
screen{on}
prompt{^[[2J}
command{echo Making %0...}
command{md %0}
wait{0,Press any key to continue.}
screen{off}
select{<RMDIR> Remove Directory}
input{0,Enter directory name: }
getkey{Press <ESC> to abort, <RETURN> to continue.}
option{27}
prompt{}
option{13}
screen{on}
prompt{^[[2J}
command{echo Removing %0...}
command{rd %0}
wait{0,Press any key to continue.}
screen{off}
Page 19
menudef{3} Disk Commands
title{ Disk Commands }
select{Return to Main Menu}
menu{0}
select{<CHKDSK> Check Disk}
input{0,1c,Enter chkdsk parameter: }
screen{on}
prompt{^[[2J}
command{chkdsk %0}
wait{0,Press any key to continue.}
screen{off}
select{<FORMAT> Format Disk}
getkey{Press <ESC> to abort, A for drive A:, or B for drive B:}
option{27} esc
prompt{}
option{65,97} A
screen{on}
prompt{^[[2J}
command{format a:}
screen{off}
option{66,98} B
screen{on}
prompt{^[[2J}
command{format b:}
screen{off}
select{<DISKCOPY> Copy Disk}
input{0,1c,Enter source drive letter: }
input{1,1c,Enter destination drive letter: }
screen{on}
prompt{^[[2J}
command{diskcopy %0: %1:}
screen{off}
select{<SYS> Put Dos on Disk}
getkey{Press <ESC> to abort, A for drive A:, or B for drive B:}
option{27} esc
prompt{}
option{65,97} A
wait{13,Place disk in drive A: and press <RETURN>}
screen{on}
prompt{^[[2J}
command{sys a:}
screen{off}
option{66,98} B
wait{13,Place disk in drive B: and press <RETURN>}
screen{on}
prompt{^[[2J}
command{sys b:}
screen{off}
Page 20
select{Copy Command.com to Disk}
getkey{Press <ESC> to abort, A for drive A:, or B for drive B:}
option{27} esc
prompt{}
option{65,97} A
wait{13,Place disk in drive A: and press <RETURN>}
prompt{Coping Command.com...}
command{copy \command.com a:}
prompt{}
option{66,98} B
wait{13,Place disk in drive B: and press <RETURN>}
prompt{Coping Command.com...}
command{copy \command.com b:}
prompt{}
menudef{4} System Commands
title{ System Commands }
select{Return to Main Menu}
menu{0}
select{<DATE> Set system date}
screen{on}
prompt{^[[2J}
command{date}
screen{off}
select{<TIME> Set system time}
screen{on}
prompt{^[[2J}
command{time}
screen{off}
select{<SET> Set environment}
input{0,Enter set parameters: }
screen{on}
prompt{^[[2J}
command{set %0}
wait{0,Press any key to continue.}
screen{off}
Page 21
5. PROGRAM SPECIFICATIONS
5.1. Hardware Requirements
IBM PC, XT, AT, or compatable. 256K memory and one disk drive.
5.2. Memory Requirements
5.2.1. DOS Calls with Command{}
When a command{} statement is issued, command.com is
reloaded and given a command line. There must be enough
free memory above the menu program to load command.com
and any program called by command.com. There is enough
stack and heap space to allow twenty menus with the
maximum selections each. The entire program takes only
90K of memory.
5.2.2. Menu Definitions and Getkey Options
The program is currently limited to a maximum of twenty
menudef{} statements per menu file, and a maximum of
twenty option{} statements for each getkey{}. The reason
is because the control pointers used in the program are
stored in a fixed length array. If you need to define more
menus, then use another menu file and call it with a
menu{} statement.
5.2.3. Program Statements
Each recognized program statment is converted to a
function pointer and added to a linked list. Each node in
the linked list occupies 10 bytes, and there is a buffer
allocated for the parameters passed to each function call.
5.2.4. Internal Requirements
Two video buffers are used and each require 4000 bytes.
Page 22
5.3. Program Limitations
Only one statement may be placed on a line.
Line lengths are limited to 256 bytes.
Maximum of 20 menudef{} statements per file.
Maximum of 20 options{} for each getkey{}.
Maximum of 20 select{} statements for each menudef{}.
Maximum of 3 major menu title lines.
Maximum of 2 menu title lines.
Maximum of 10 (%0-%9) user variables. Each 80 characters.
Available stack space dictates the maximum nesting
level for menu files.